* Merge Auction Data with Price Data

global data "$replication\Data"
global inter "$replication\Dta - Intermediate"
global final "$replication\Dta - Final"
global graphs "$replication\Graphs"

use "$inter\PricesAuctionsMerged_New.dta", clear
drop _merge
merge m:1 isin iss_my using "$inter\Outstandings_Monthly.dta"

drop if isin==""
drop if _merge == 2
duplicates drop
sort isin iss_my

* Since the merge is done using the issuance date, we only have information about the months to maturity
* on those dates. To fill this info, we substract 1 month to the mon2mat variable for every month that elapses.
* This is done if and only if there are no reissuances (i.e. if mon2mat==.) and if the outstanding is not 0.
by isin: replace mon2mat=(mon2mat[_n-1]-1) if (mon2mat==. & out_ngdp!=0)
keep if mon2mat!=.
drop if mon2mat < 0
drop _merge

gen totalot_ngdp=totalot/nom_gdp
* Generating categories by matutiry: 3, 6, 9, 12, 18 months and 3, 5, 10, 15, 30 and 50 years



save "$inter\PricesAuctionsMerged_New.dta", replace

